<?php
/**
 * Created by PhpStorm.
 * User: wanghaibo
 * Date: 18/1/31
 * Time: 17:17
 */

namespace app\message\controller;


use app\message\model\MessageModel;
use cmf\controller\HomeBaseController;
use think\Loader;
class IndexController extends HomeBaseController
{
    private $manager;
    public function index(){
        if(session('?flush')){
            $this->assign('data',session('flush'));
            session('flush',null);
        }
        return $this->fetch();
    }
    public function post(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $val = Loader::validate('Message');
            if (!$check = $val->check($data)) {
                session('flush',$data);
                $this->error($val->getError(),url('index#message'),'',3);
            }else{
                $this->manager = new MessageModel();
                if($res = $this->manager->addMessage($data)){
                    $this->success('提交成功',url('index'));
                }else{
                    $this->error('提交失败',url('index#message'));
                }
            }

        }
    }

}